<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系电话"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleBatchSignIn"
        >批量签到</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" prop="name" />
      <el-table-column label="工作单位" prop="workUnit" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="性别" prop="gender" width="80">
        <template slot-scope="scope">
          <span>{{ ['1', '2'].includes(scope.row.gender) ? (scope.row.gender === '1' ? '男' : '女') : '' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="科室" prop="department" :show-overflow-tooltip="true" />
      <el-table-column label="职称" prop="title" />
      <el-table-column label="联系电话" prop="contactPhone" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="分支机构" prop="branchOrg" />
      <el-table-column label="分支机构任职" prop="branchPosition" width="120" />
      <el-table-column label="执业医师资格证" prop="qualification" width="130" />
      <el-table-column label="电子邮箱" prop="email" :show-overflow-tooltip="true" />
      <el-table-column label="是否住宿" prop="isLive" width="100">
        <template slot-scope="scope">
          <span>{{ ['0', '1'].includes(scope.row.isLive) ? (scope.row.isLive === '1' ? '是' : '否') : '' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否需要乘坐班车" prop="isBus" width="130">
        <template slot-scope="scope">
          <span>{{ ['0', '1'].includes(scope.row.isBus) ? (scope.row.isBus === '1' ? '是' : '否') : '' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否已报名" prop="hasSigned" width="100">
        <template slot-scope="scope">
          <span>{{ ['0', '1'].includes(scope.row.hasSigned) ? (scope.row.hasSigned === '1' ? '是' : '否') : '' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="120" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)">编辑</el-button>
          <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="dialogVisible" width="500px" append-to-body :close-on-click-modal="false">
      <el-form :model="form" :rules="rules" ref="form" label-width="110px" style="height: 580px; overflow: auto">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-radio-group v-model="form.gender">
            <el-radio label="1">男</el-radio>
            <el-radio label="2">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入联系电话" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="所在地区" prop="location">
          <el-input v-model="form.location" placeholder="请输入所在地区" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证号" clearable maxlength="18" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="工作单位" prop="workUnit">
          <el-input v-model="form.workUnit" placeholder="请输入工作单位" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="科室" prop="department">
          <el-input v-model="form.department" placeholder="请输入科室" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="职称" prop="title">
          <el-input v-model="form.title" placeholder="请输入职称" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="分支机构" prop="branchOrg">
          <el-input v-model="form.branchOrg" placeholder="请输入分支机构" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="分支机构任职" prop="branchPosition">
          <el-input v-model="form.branchPosition" placeholder="请输入分支机构任职" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="执业医师资格证" prop="qualification">
          <el-input v-model="form.qualification" placeholder="请输入执业医师资格证" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="电子邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入电子邮箱" clearable style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="是否住宿" prop="isLive">
          <el-radio-group v-model="form.isLive">
            <el-radio :label="'1'">是</el-radio>
            <el-radio :label="'0'">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否需要乘坐班车" prop="isBus">
          <el-radio-group v-model="form.isBus">
            <el-radio :label="'1'">是</el-radio>
            <el-radio :label="'0'">否</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getRole,
} from "@/api/system/role";
import {addMeetUser, batchSignIn, delMeetUser, listMeetUser, updateMeetUser} from "@/api/meetingManagement/meetUser";

export default {
  name: "AttendeeManagement",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        phone: undefined
      },
      // 表单参数
      form: {
        name: null,
        contactPhone: null,
        location: null,
        idCard: null,
        workUnit: null,
        department: null,
        title: null,
        branchOrg: null,
        branchPosition: null,
        qualification: null,
        email: null,
        hasSigned: null,
        isLive: null,
        isBus: null,
        remark: null
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        contactPhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ]
      },
      dialogVisible: false
    }
  },
  mounted() {
    this.queryParams.meetId = this.$route.params && this.$route.params.id
    this.getList()
  },
  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = true
      listMeetUser(this.addDateRange(this.queryParams)).then(response => {
          this.roleList = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },
    // 取消按钮
    cancel() {
      this.dialogVisible = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        name: null,
        contactPhone: null,
        location: null,
        idCard: null,
        workUnit: null,
        department: null,
        title: null,
        branchOrg: null,
        branchPosition: null,
        qualification: null,
        email: null,
        hasSigned: null,
        isLive: null,
        isBus: null,
        remark: null
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.name = null
      this.queryParams.phone = null
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.dialogVisible = true
      this.title = "添加参会人员"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      this.form = {...row}
      this.dialogVisible = true
      this.title = "修改参会人员"
    },
    /** 批量签到按钮操作 */
    handleBatchSignIn() {
      console.log(this.ids)
      this.$modal.confirm('是否确认批量签到选中的参会人员？').then(() => {
        console.log("222222222222222222222",this.ids)
        return batchSignIn(this.ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("批量签到成功")
      }).catch(() => {
        this.$modal.msgError("批量签到失败")
      })
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.meetId = this.queryParams.meetId
          if (this.form.id != undefined) {
            updateMeetUser(this.form).then(response => {
              this.$modal.msgSuccess(response.msg || "修改成功")
              this.dialogVisible = false
              this.getList()
            })
          } else {
            addMeetUser(this.form).then(response => {
              this.$modal.msgSuccess(response.msg || "新增成功")
              this.dialogVisible = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id
      this.$modal.confirm('是否确认删除参会人员编号为"' + id + '"的数据项？').then(function() {
        return delMeetUser(id)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    }
  }
}
</script>
<style>
.el-radio input[aria-hidden="true"] {
  display: none !important;
}

.el-radio:focus:not(.is-focus):not(:active):not(.is-disabled) .el-radio__inner {
  box-shadow: none !important;
}

</style>
